#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<list>
#include<cstdlib>
#include<cmath>
#include<sstream>
#include<numeric>
#include<cstdio>
#include<cstring>
#include<stack>
#define PI acos(-1)
#define MP make_pair
#define PB push_back
#define VI vector <int>
#define PII pair <int,int>
#define LL long long
#define SET(v,i) memset(v, i, sizeof(v))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORD(i,a,b) for (int i = (a); i >= (b); i--)
#define FORN(i,a,b) for (int i = (a); i < (b); i++)
#define DOWN(i,a,b) for (int i = (a); i > (b); i--)
#define FIT(it,v) for (typeof(v.begin()) it = v.begin(); it != v.end(); it++)
#define FITD(it,v) for (typeof(v.rbegin()) it = v.rbegin(); it != v.rend(); it++)
using namespace std;
//change a to b by mini operation ans(1. a=a-1 2. a=a-a%x x=[2,k]) a,b=[1,10^18] k=[2,15] 
const int N=360360+5;
LL dp[N];
template<class T>
inline T gcd(T a,T b){
    if(a<b)swap(a,b);
    for(T r;b;r=a%b,a=b,b=r);
    return a;   
    } 
LL cal(LL a,LL b,LL k){
	dp[0]=0;
	for(int i=1;i<=a-b;i++){
		dp[i]=dp[i-1]+1;
		for(int j=2;j<=k;j++)if((b+i)%j<=i)dp[i]=min(dp[i],dp[i-(b+i)%j]+1);
		}
	return dp[a-b];
	}
int main(){
	LL a,b,k;
	while(cin>>a>>b>>k){
		int c=1;
		for(int i=2;i<=k;i++)c=c*i/gcd(c,i);
		if(a/c==b/c)cout<<cal(a%c,b%c,k)<<endl;
		else cout<<cal(a%c,0,k)+cal(c,b%c,k)+cal(c,0,k)*(a/c-(b+c-1)/c)<<endl;
		}
    return 0;
    }
